package S04;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public class F02 {
	public static void main(String[] args) {
        // 1. 获取当前日期和时间
        LocalDateTime now = LocalDateTime.now();
        System.out.println("当前日期和时间: " + now);

        // 2. 创建指定日期和时间的对象
        LocalDateTime specificDateTime = LocalDateTime.of(2025, 10, 1, 14, 30, 45);
        System.out.println("指定的日期和时间: " + specificDateTime);

        // 3. 获取日期和时间的各个部分
        int year = now.getYear();
        int month = now.getMonthValue();
        int day = now.getDayOfMonth();
        int hour = now.getHour();
        int minute = now.getMinute();
        int second = now.getSecond();

        System.out.println("年份: " + year);
        System.out.println("月份: " + month);
        System.out.println("日期: " + day);
        System.out.println("小时: " + hour);
        System.out.println("分钟: " + minute);
        System.out.println("秒: " + second);

        // 4. 修改日期和时间
        LocalDateTime futureDateTime = now.plusDays(10).plusHours(5);
        System.out.println("10天后，5小时后的日期和时间: " + futureDateTime);

        // 5. 格式化日期和时间
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        String formattedDateTime = now.format(formatter);
        System.out.println("格式化后的日期和时间: " + formattedDateTime);

        // 6. 解析日期和时间字符串
        String dateTimeString = "2025-06-01 12:30:45";
        LocalDateTime parsedDateTime = LocalDateTime.parse(dateTimeString, formatter);
        System.out.println("解析后的日期和时间: " + parsedDateTime);
    }
}
